package com.yc.testupload.publisher;

import com.yc.testupload.model.Account;
import com.yc.testupload.model.PublishResult;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.Map;

/**
 * 抖音平台发布器
 * 实现抖音平台的内容发布功能
 */
public class DouyinPublisher implements PlatformPublisher {
    private static final Logger logger = LogManager.getLogger(DouyinPublisher.class);
    private static final String PLATFORM_TYPE = "douyin";

    @Override
    public PublishResult publish(Account account, Map<String, Object> content) {
        logger.info("开始发布到抖音平台，账号: {}", account.getAccountName());

        // 模拟抖音平台发布过程
        try {
            // 这里应该是调用抖音API的实际代码
            // 目前仅做模拟
            String articleTitle = content.getOrDefault("title", "").toString();
            String articleContent = content.getOrDefault("content", "").toString();

            logger.info("抖音发布内容 - 标题: {}, 账号ID: {}", articleTitle, account.getAccountId());

            // 模拟发布延迟
            Thread.sleep(1200);

            PublishResult result = new PublishResult(true, "抖音平台发布成功");
            result.setPlatformResponse("抖音平台返回: OK, douyin_id=dy_" + System.currentTimeMillis());
            logger.info("抖音平台发布完成，账号: {}", account.getAccountName());
            return result;
        } catch (Exception e) {
            logger.error("抖音平台发布失败: {}", e.getMessage(), e);
            PublishResult result = new PublishResult(false, "抖音平台发布失败: " + e.getMessage());
            return result;
        }
    }

    @Override
    public String getPlatformType() {
        return PLATFORM_TYPE;
    }
}